package bmatch.tech.cloud.dao.builder;

import org.apache.ibatis.jdbc.SQL;
import org.springframework.stereotype.Component;

/**
 * FileModelSqlBuilder的注释
 *
 * @author: Awake
 * @date: 2018-12-05 19:11
 **/
@Component
public class FileModelSqlBuilder {

    public String query(String userId, String path, String name) {

        return new SQL() {{
            SELECT(
                    "id,user_id as userId,type,name,path,gmt_created as gmtCreated,store_path as storePath");
            FROM("file_model");
            WHERE("user_id = #{userId,jdbcType=VARCHAR}");
            if (path != null) {
                WHERE("path = #{path,jdbcType=VARCHAR}");
            } else if (name != null) {
                WHERE("name = #{name,jdbcType=VARCHAR}");
            }
            ORDER_BY("id");
        }}.toString();
    }
}
